<!-- 上传资料页 -->
<template>
<section class="upload-info-detail">
    <!-- 客户基础信息 -->
    <baseInfo :accountBillData="accountBillData"/>

    <!-- 库存信息 / 工资信息 / 银行流水 -->
    <inventoryInfo
        ref="inventoryInfo"
        :uploadInfo="uploadInfo"
        :fatherType="1"
        :accountBillData="accountBillData"/>

    <!-- 发票上传 -->
    <uploadInvoice
        ref="uploadInvoice"
        :isSinglePart="true"
        :uploadInfo="uploadInfo"
        @uploadBankFinished="getUploadBankFinished"
        :accountBillData="accountBillData"/>


    <!-- 分录信息 -->
    <artificialInfo
        ref="artificialInfo"
        :accountBillData="accountBillData"
        :artificialInput="artificialInput"/>
    <footer>
        <el-button type="primary" :disabled="!uploadBankFinished" @click="save" size="mini">{{ uploadBankFinished? "保存": "请稍后" }} </el-button>
    </footer>
</section>
</template>
<script>
/**
 * @file 上传资料页
 */

import 'element-ui/lib/theme-chalk/switch.css';
import baseInfo from './components/baseInfo';
import inventoryInfo from './components/inventoryInfo';
import uploadInvoice from './components/uploadInvoice';
import artificialInfo from './components/artificialInfo';

export default {
    components: {
        baseInfo,
        inventoryInfo,
        uploadInvoice,
        artificialInfo
    },
    data() {
        const str = localStorage.getItem('currentAccountBill');
        const data = JSON.parse(str);

        return {
            switchValue: false,
            accountBillData: data,
            // 上传状态信息
            uploadInfo: null,
            // 分录信息
            artificialInput: [],
            uploadBankFinished: false,
        };
    },
    created() {
        // 获取上传相关信息
        this.$http.post('/accountBills/getInfo', {
            companyName: this.accountBillData.companyName
        }).then(res => {
            this.uploadInfo = res.data.customerUploadInfo;
            this.artificialInput = res.data.artificialInput || [];
        }).catch(err => {
        });
    },
    //   async created() {
    //     // 获取上传相关信息
    //     console.log("上传相关信息获取成功：", this.uploadInfo);
    //      var responseData = await this.$http.post('/accountBills/getInfo', {
    //         companyName: this.accountBillData.companyName
    //     });

    //     this.uploadInfo = responseData.customerUploadInfo;
    //     this.artificialInput = responseData.artificialInput || [];
    //     console.log("上传相关信息获取成功：", responseData);
    // },
    methods: {

        /**
         * 保存
         */
        save() {
            const inventoryInfo = this.$refs.inventoryInfo.getValue();
            const uploadInvoice = this.$refs.uploadInvoice.getValue();
            const artificialInfo = this.$refs.artificialInfo.getValue();

            const params = {
                companyName: this.accountBillData.companyName,
                ...inventoryInfo,
                ...uploadInvoice,
                artificialInput: artificialInfo
            };

            this.$http.post('/accountBills/saveInfo', params).then(res => {
                this.$router.push('/upload-info/list');
            });
        },
        getUploadBankFinished(uploadBankFinished){
            this.uploadBankFinished = uploadBankFinished;
        }
    }
}
</script>
<style lang="less" scoped>
@import '../../assets/var.less';
.upload-info-detail {
    padding: 0 10px;

    footer {
        text-align: center;
        padding: 20px;
        .el-button {
            min-width: 130px;
        }
    }
}
</style>
